home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / source.exe / POSIX / SH / STD / STDC / CLOCK.C next >
C/C++ Source or Header  |  1992-07-13  |  735b  |  58 lines

  1. /* clock() */
  2.  
  3. #include <time.h>
  4.  
  5. #if _BSD
  6.  
  7. #include <sys/time.h>
  8. #include <sys/resource.h>
  9.  
  10. clock_t
  11. clock()
  12. {
  13.     struct timeval tv;
  14.     struct rusage ru;
  15.  
  16.     getrusage(RUSAGE_SELF, &ru);
  17.     tv.tv_sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
  18.     tv.tv_usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
  19.     return tv.tv_sec*CLK_TCK + (long)tv.tv_usec*CLK_TCK/1000000;
  20. }
  21.  
  22. #endif
  23.  
  24. #if _V7 || _SYSV
  25.  
  26. #include <sys/times.h>
  27.  
  28. clock_t
  29. clock()
  30. {
  31.     struct tms tms;
  32.  
  33.     (void) times(&tms);
  34.     return tms.tms_utime + tms.tms_stime;
  35. }
  36.  
  37. #endif
  38.  
  39. #if _ST
  40.  
  41. #include <osbind.h>
  42.  
  43. clock_t
  44. clock()
  45. {
  46.     long save;
  47.     clock_t c;
  48.  
  49.     /* access the ST's 200 HZ system clock in protected memory */
  50.     save = Super(0L);
  51.     c = *((long *)0x04BA);
  52.     (void)Super(save);
  53.     return c;
  54. }
  55.  
  56. #endif
  57.  
  58.